<template>
    <div>
        <el-dialog :title="title" :visible.sync="value" :before-close="close" center>
            <el-form :model="form">
                <el-form-item label="人员名称：" :label-width="formLabelWidth">
                    <el-input type="text" placeholder="请输入" v-model="form.name" maxlength="5" show-word-limit
                        style="width:350px">
                    </el-input>
                </el-form-item>
                <el-form-item label="角色：" :label-width="formLabelWidth">
                    <el-select v-model="form.region" placeholder="请选择" style="width:350px">
                        <el-option label="运营者" value="shanghai"></el-option>
                        <el-option label="运维者" value="beijing"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="联系电话：" :label-width="formLabelWidth">
                    <el-input type="text" placeholder="请输入" v-model="form.name" maxlength="11" show-word-limit
                        style="width:350px">
                    </el-input>
                </el-form-item>
                <el-form-item label="负责区域：" :label-width="formLabelWidth">
                    <el-select v-model="form.region" placeholder="请选择" style="width:350px">
                        <el-option label="运营者" value="shanghai"></el-option>
                        <el-option label="运维者" value="beijing"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="头像：" :label-width="formLabelWidth">
                    <el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/"
                        :show-file-list="true" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
                        <img v-if="imageUrl" :src="imageUrl" class="avatar">
                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                    </el-upload>
                    <span style="color:gray">支持扩展名:jpg、png,文件不得大于100kb</span>
                </el-form-item>
                <el-form-item label="状态：" :label-width="formLabelWidth">
                    <el-checkbox v-model="checked">是否启用</el-checkbox>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="close">取 消</el-button>
                <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
            </div>
        </el-dialog>

    </div>
</template>
<script>
export default {
    name: '',
    props: {
        value: {
            type: Boolean
        },
        title: {
            type: String
        }
    },
    data() {
        return {
            dialogFormVisible: false,
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            formLabelWidth: '120px',
            imageUrl: '',
            checked: false
        }
    },
    methods: {
        close() {
            this.$emit('input', false)
            this.$options.data()
        },

        handleAvatarSuccess(res, file) {
            this.imageUrl = URL.createObjectURL(file.raw);
        },
        beforeAvatarUpload(file) {
            const isJPG = file.type === 'image/jpg' || file.type === 'image/png';
            const isLt2M = file.size / 10000 < 1;

            if (!isJPG) {
                this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
            }
            if (!isLt2M) {
                this.$message.error('上传头像图片大小不能超过 100k!');
            }
            return isJPG && isLt2M;
        }
    }
}
</script>
<style lang="scss">
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.avatar-uploader .el-upload:hover {
    border-color: #409EFF;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 100px;
    height: 100px;
    line-height: 100px;
    text-align: center;
}

.avatar {
    width: 100px;
    height: 100px;
    display: block;
}
</style>